function ref = createRef(trajektorie, Ts)
X=trajektorie(1,:);
Y=trajektorie(2,:);
psi=atan2(diff(Y),diff(X));
psi=[psi,psi(end)];
% negPsi=psi(psi<0)+2*pi;
% psi(psi<0)=negPsi;
dpsi=[diff(psi)/Ts];
dpsi=[dpsi,dpsi(end)];
dx=zeros(1,length(dpsi));
dy=zeros(1,length(dpsi));
dX=[diff(X)/Ts];
dX=[dX,dX(end)];
dY=[diff(Y)/Ts];
dY=[dY,dY(end)];
for i=1:length(psi)
    rot=[cos(psi(i)),sin(psi(i));...
        -sin(psi(i)),cos(psi(i))];
    vel=inv(rot)*[dY(i);dX(i)];
    dy(i)=vel(1);
    dx(i)=vel(2);
end
delka=length(dx);
ref=[dy,ones(1,delka*3)*dy(end);...
    dx,ones(1,delka*3)*dx(end);...
    psi,cumsum(ones(1,delka*3)*dpsi(end))+psi(end);...
    dpsi,ones(1,delka*3)*dpsi(end);...
    Y,cumsum(Ts*dx(end)*sin(cumsum(ones(1,delka*3)*dpsi(end))+psi(end))+Ts*dy(end)*cos(cumsum(ones(1,delka*3)*dpsi(end))+psi(end)))+Y(end);...
    X,cumsum(Ts*dx(end)*cos(cumsum(ones(1,delka*3)*dpsi(end))+psi(end))-Ts*dy(end)*sin(cumsum(ones(1,delka*3)*dpsi(end))+psi(end)))+X(end)];
end